package edu.siu.math.egut.main;

import java.awt.Component;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

import sun.misc.Regexp;

import com.sun.tools.javac.util.List;

import edu.siu.math.egut.io.Algorithms;
import edu.siu.math.egut.io.LiE;
import edu.siu.math.egut.io.OutputPref;
import edu.siu.math.egut.local.Inequality;
import edu.siu.math.egut.local.InequalityReadException;
import edu.siu.math.egut.local.SectionIntegral;
import edu.siu.math.egut.local.SectionIntegral.UnipotentPrefixPair;
import edu.siu.math.egut.util.BadSubstitutionException;
import edu.siu.math.egut.util.Group;
import edu.siu.math.egut.util.Matrix;
import edu.siu.math.egut.util.Monomial;
import edu.siu.math.egut.util.MonomialReadException;
import edu.siu.math.egut.util.NoSuchElementException;
import edu.siu.math.egut.util.NonlinearException;
import edu.siu.math.egut.util.NotARootException;
import edu.siu.math.egut.util.Parabolic;
import edu.siu.math.egut.util.Polynomial;
import edu.siu.math.egut.util.PolynomialReadException;
import edu.siu.math.egut.util.Sunipotent;
import edu.siu.math.egut.util.Unipotent;
import edu.siu.math.egut.util.UnipotentReadException;
import edu.siu.math.egut.util.VectorCayleyTable;
import edu.siu.math.egut.util.WeylWord;
import edu.siu.math.egut.util.WeylWordReadException;

/**
 * The class will be used for testing the classes
 * in the egut package.  It's content will vary 
 * wildly based on what specifically I am trying 
 * to test, and it will eventually be deleted.
 * @author Joseph Hundley
 *
 */


public class driver {

	
    private static final String TEST_TEX = "$$\n\n\\int_{F_4(F)\\backslash F_4(\\mathbb{A})} \\varphi_{\\pi}(g) E_{\\tau}(g,s) \\theta(g) \\, dg.$$\n\n";
    private static final String TEST_TEX_PART2 = "This would be considered an example of a reductive type integral.";


    public static void main(String[] args) throws IOException, NotARootException, WeylWordReadException, BadSubstitutionException, InequalityReadException, PolynomialReadException, MonomialReadException, NoSuchElementException{

	int[][] uRoots = {{0,1},{1,1},{2,1},{3,1},{3,2}};
	
	Group g = Group.G2;
	
	Polynomial ell = Polynomial.read("u_{01}+u_{31}");
	String test1 = "x_{10}(1)";
	String test2 = "x_{-10}(-1)";
	
	String[] test = {test1, test2, test1};
	
	final Unipotent u = new Unipotent(g, uRoots, "u");
	final Unipotent u1 = new Unipotent(g, uRoots, "u");

	Scanner scanner = new Scanner(System.in);
	say( "Type x_{10}(1)");
	String test3 = scanner.next();
	say( "Type x_{-10}(-1)");
	String test4 = scanner.next();
	String[] commands = {test3,test4,test3};
	
	// treat remaining args as specifying group elements by which to
	// act
	for (int i = commands.length - 1; i > -1; i--) { // we start with the

		    u.stateNumberOfAssociations();
		    u.actBy(commands[i]);
		    u.stateNumberOfAssociations();
		    ell = u.chOfVars(ell);
		    u.stateNumberOfAssociations();

		    
			
		    }
		    
	say(" ");
	say(" ");
	say(" ");

	    String s1 = test3;
		String s2 = test4;
		u1.stateNumberOfAssociations();
		u1.actBy(s1);
		u1.stateNumberOfAssociations();
		
		ell = u1.chOfVars(ell);
		u1.stateNumberOfAssociations();

		u1.actBy(s2);
		u1.stateNumberOfAssociations();
		ell = u1.chOfVars(ell);
		u1.stateNumberOfAssociations();
		u1.actBy(s1);
		u1.stateNumberOfAssociations();
		ell = u1.chOfVars(ell);
		u1.stateNumberOfAssociations();


		
	
	// print message for completion.
	say("Process completed.");
	

    
    }


    private static void doIt(String var) {
	say(var + SectionIntegralCalculator.QUIT_PATTERN.matcher(var).matches() + var.matches("q|Q"));
    }


    private static String message(Polynomial p1) {
	// TODO Auto-generated method stub
	return p1.toString() + "is a signed default variable: " + p1.isASignedDefaultVariable();
    }


    private static void tag(File dirFile, String s) throws IOException {
	FileWriter fw = new FileWriter(dirFile+File.separator+"tag.txt");
	fw.write(s);
	fw.close();
	
    }


    private static void say(String string) {
	System.out.println( string);
	
    }
    
 }
